package com.RMP
{
    import com.gskinner.text.*;
    import com.util.*;
    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import com.greensock.*;

    public class JobShell extends Sprite
    {
        var btnsArray:Array;
        var xmlLoader:XMLLoader;
        var fadeSpeed:Number;
        var fieldArray:Array;
        var tf:TextFlow;
        var bigField1:BigField;
        var bigField2:BigField;
        var currNavId:int;
        var myRoot:MovieClip;
        var longText:LongText;
        public var myXML:XMLList;
        var navItem:NavItem;
        var styler:StyleSheet;
        var myId:int;
        var navArray:Array;

        public function JobShell(param1:MovieClip, param2:Number, param3:int) : void
        {
            var mR:* = param1;
            var fSpeed:* = param2;
            var incomingId:* = param3;
            myRoot = mR;
            fadeSpeed = fSpeed;
            myId = incomingId;
            trace("myId " + myId);
            buildStyles();
            navArray = new Array("Apply by Mail", "View All Job Listings");
            btnsArray = new Array();
            trace("myRoot.pathNames " + myRoot.pathNames);
            switch(myRoot.pathNames[2])
            {
                case "new-york":
                {
                    var _loc_6:int = 0;
                    var _loc_9:int = 0;
                    var _loc_12:int = 0;
                    var _loc_13:* = myRoot.myXML.nav.contact.tier0;
                    var _loc_11:* = new XMLList("");
                    for each (_loc_14 in _loc_13)
                    {
                        
                        var _loc_15:* = _loc_13[_loc_12];
                        with (_loc_13[_loc_12])
                        {
                            if (@label == "Employment")
                            {
                                _loc_11[_loc_12] = _loc_14;
                            }
                        }
                    }
                    var _loc_10:* = _loc_11.tier1;
                    var _loc_8:* = new XMLList("");
                    for each (_loc_11 in _loc_10)
                    {
                        
                        var _loc_12:* = _loc_10[_loc_9];
                        with (_loc_10[_loc_9])
                        {
                            if (@label == "New York")
                            {
                                _loc_8[_loc_9] = _loc_11;
                            }
                        }
                    }
                    var _loc_7:* = _loc_8.item;
                    var _loc_5:* = new XMLList("");
                    for each (_loc_8 in _loc_7)
                    {
                        
                        var _loc_9:* = _loc_7[_loc_6];
                        with (_loc_7[_loc_6])
                        {
                            if (@id == myId)
                            {
                                _loc_5[_loc_6] = _loc_8;
                            }
                        }
                    }
                    myXML = _loc_5;
                    buildLongTitle("<span class= \'myBold\'>" + myXML.@label + "</span><br>New York");
                    break;
                }
                case "los-angeles":
                {
                    var _loc_6:int = 0;
                    var _loc_9:int = 0;
                    var _loc_12:int = 0;
                    var _loc_13:* = myRoot.myXML.nav.contact.tier0;
                    var _loc_11:* = new XMLList("");
                    for each (_loc_14 in _loc_13)
                    {
                        
                        var _loc_15:* = _loc_13[_loc_12];
                        with (_loc_13[_loc_12])
                        {
                            if (@label == "Employment")
                            {
                                _loc_11[_loc_12] = _loc_14;
                            }
                        }
                    }
                    var _loc_10:* = _loc_11.tier1;
                    var _loc_8:* = new XMLList("");
                    for each (_loc_11 in _loc_10)
                    {
                        
                        var _loc_12:* = _loc_10[_loc_9];
                        with (_loc_10[_loc_9])
                        {
                            if (@label == "Los Angeles")
                            {
                                _loc_8[_loc_9] = _loc_11;
                            }
                        }
                    }
                    var _loc_7:* = _loc_8.item;
                    var _loc_5:* = new XMLList("");
                    for each (_loc_8 in _loc_7)
                    {
                        
                        var _loc_9:* = _loc_7[_loc_6];
                        with (_loc_7[_loc_6])
                        {
                            if (@id == myId)
                            {
                                _loc_5[_loc_6] = _loc_8;
                            }
                        }
                    }
                    myXML = _loc_5;
                    buildLongTitle("<span class= \'myBold\'>" + myXML.@label + "</span><br>Los Angeles");
                    break;
                }
                default:
                {
                    break;
                }
            }
            myRoot.registerPageHit("contact/employment/" + myRoot.pathNames[2] + "/" + toLowercase(myXML.@label));
            buildNav();
            buildField();
            myRoot.stage.addEventListener(Event.RESIZE, onResizer, false, 0, true);
            return;
        }

        function doResize() : void
        {
            var _loc_1:int = 0;
            var _loc_2:int = 0;
            if (longText != null)
            {
                longText.x = Math.round(4 * (myRoot.unitW + myRoot.gutterW));
                longText.y = myRoot.headerH + (myRoot.unitH + myRoot.gutterH) - 4 * myRoot.unitW / 75;
                var _loc_3:* = myRoot.unitW / 75;
                longText.field.scaleY = myRoot.unitW / 75;
                longText.field.scaleX = _loc_3;
            }
            if (btnsArray != null)
            {
                _loc_1 = 0;
                while (_loc_1 < btnsArray.length)
                {
                    
                    var _loc_3:* = myRoot.unitW / 75;
                    btnsArray[_loc_1].field.scaleY = myRoot.unitW / 75;
                    btnsArray[_loc_1].field.scaleX = _loc_3;
                    btnsArray[_loc_1].x = Math.round(8 * (myRoot.unitW + myRoot.gutterW) - 3 * myRoot.unitW / 75);
                    btnsArray[_loc_1].y = Math.round(myRoot.headerH + (myRoot.unitH + myRoot.gutterH) + -5 * myRoot.unitW / 75 + 14 * _loc_1 * myRoot.unitW / 75);
                    _loc_1++;
                }
            }
            if (fieldArray != null)
            {
                _loc_2 = 0;
                while (_loc_2 < fieldArray.length)
                {
                    
                    var _loc_3:* = myRoot.unitW / 75;
                    fieldArray[_loc_2].scaleY = myRoot.unitW / 75;
                    fieldArray[_loc_2].scaleX = _loc_3;
                    fieldArray[_loc_2].x = Math.round(_loc_2 * 4 * (myRoot.unitW + myRoot.gutterW));
                    fieldArray[_loc_2].y = Math.round(myRoot.headerH + 2 * (myRoot.unitH + myRoot.gutterH));
                    _loc_2++;
                }
            }
            return;
        }

        function buildField() : void
        {
            bigField1 = new BigField();
            bigField1.name = "bigField1";
            bigField1.field.antiAliasType = AntiAliasType.ADVANCED;
            bigField1.field.gridFitType = GridFitType.PIXEL;
            bigField1.field.selectable = true;
            bigField1.field.embedFonts = true;
            bigField1.field.multiline = true;
            bigField1.field.wordWrap = true;
            bigField1.field.styleSheet = styler;
            addChild(bigField1);
            bigField2 = new BigField();
            bigField2.name = "bigField2";
            bigField2.field.antiAliasType = AntiAliasType.ADVANCED;
            bigField2.field.gridFitType = GridFitType.PIXEL;
            bigField2.field.selectable = true;
            bigField2.field.embedFonts = true;
            bigField2.field.multiline = true;
            bigField2.field.wordWrap = true;
            bigField2.field.styleSheet = styler;
            addChild(bigField2);
            fieldArray = new Array(bigField1, bigField2);
            bigField1.field.htmlText = "<p><span class = \'myBold\'>Job Description</span><br>" + myXML.longTitle + "</p>";
            var _loc_3:int = 0;
            var _loc_4:* = myRoot.myXML.nav.contact.tier0;
            var _loc_2:* = new XMLList("");
            for each (_loc_5 in _loc_4)
            {
                
                var _loc_6:* = _loc_4[_loc_3];
                with (_loc_4[_loc_3])
                {
                    if (@label == "General Info")
                    {
                        _loc_2[_loc_3] = _loc_5;
                    }
                }
            }
            bigField2.field.htmlText = "<p>" + _loc_2.tier1.item.instructions + "</p>";
            doResize();
            return;
        }

        function onResizer(event:Event)
        {
            doResize();
            return;
        }

        function buildLongTitle(param1:String) : void
        {
            longText = new LongText(myRoot, param1);
            addChild(longText);
            return;
        }

        function btnRollOver(event:MouseEvent) : void
        {
            TweenMax.to(event.currentTarget, fadeSpeed, {tint:myRoot.hotColor, overwrite:true});
            return;
        }

        function toLowercase(param1:String) : String
        {
            var _loc_2:String = null;
            var _loc_3:* = undefined;
            _loc_2 = "";
            _loc_3 = 0;
            while (_loc_3 < param1.length)
            {
                
                if (param1.charAt(_loc_3) == " ")
                {
                    _loc_2 = _loc_2 + "-";
                }
                else
                {
                    _loc_2 = _loc_2 + param1.charAt(_loc_3).toLowerCase();
                }
                _loc_3 = _loc_3 + 1;
            }
            return _loc_2;
        }

        function btnRollOut(event:MouseEvent) : void
        {
            if (event.currentTarget.idNum != currNavId)
            {
                TweenMax.to(event.currentTarget, fadeSpeed, {tint:myRoot.coldColor, overwrite:true});
            }
            return;
        }

        function btnClick(event:MouseEvent) : void
        {
            currNavId = event.currentTarget.idNum;
            if (event.currentTarget.idNum == 1)
            {
                updateAddress();
            }
            return;
        }

        function buildNav() : void
        {
            var _loc_1:int = 0;
            currNavId = 0;
            _loc_1 = 0;
            while (_loc_1 < navArray.length)
            {
                
                btnsArray[_loc_1] = new NavItem(myRoot, navArray[_loc_1], "", _loc_1);
                btnsArray[_loc_1].addEventListener(MouseEvent.MOUSE_OVER, btnRollOver, false, 0, true);
                btnsArray[_loc_1].addEventListener(MouseEvent.MOUSE_OUT, btnRollOut, false, 0, true);
                btnsArray[_loc_1].addEventListener(MouseEvent.CLICK, btnClick, false, 0, true);
                btnsArray[_loc_1].alpha = 0;
                addChild(btnsArray[_loc_1]);
                if (_loc_1 == 0)
                {
                    TweenMax.to(btnsArray[_loc_1], fadeSpeed, {alpha:1, tint:myRoot.hotColor, overwrite:true});
                }
                else
                {
                    TweenMax.to(btnsArray[_loc_1], fadeSpeed, {alpha:1, overwrite:true});
                }
                _loc_1++;
            }
            currNavId = 0;
            return;
        }

        function buildStyles() : void
        {
            var _loc_1:* = undefined;
            var _loc_2:* = undefined;
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            var _loc_6:Object = null;
            var _loc_7:* = undefined;
            var _loc_8:Object = null;
            _loc_1 = new HelveticaLightEmbed().fontName;
            _loc_2 = new HelveticaBoldEmbed().fontName;
            styler = new StyleSheet();
            _loc_3 = new Object();
            _loc_3.color = myRoot.coldColorHTML;
            _loc_3.fontFamily = _loc_1;
            _loc_3.leading = -4;
            _loc_4 = new Object();
            _loc_4.color = myRoot.coldColorHTML;
            _loc_4.textDecoration = "underline";
            _loc_5 = new Object();
            _loc_5.color = myRoot.hotColorHTML;
            _loc_5.textDecoration = "underline";
            _loc_6 = new Object();
            _loc_6.color = myRoot.coldColorHTML;
            _loc_6.fontFamily = _loc_2;
            _loc_7 = new HelveticaItalicEmbed().fontName;
            _loc_8 = new Object();
            _loc_8.color = myRoot.coldColorHTML;
            _loc_8.fontFamily = _loc_7;
            styler.setStyle(".myItalic", _loc_8);
            styler.setStyle("p", _loc_3);
            styler.setStyle("a:link", _loc_4);
            styler.setStyle("a:hover", _loc_5);
            styler.setStyle(".mybold", _loc_6);
            return;
        }

        function updateAddress() : void
        {
            switch(myRoot.pathNames[2])
            {
                case "new-york":
                {
                    myRoot.clickPathNames = ["contact", "employment", "new-york", myRoot.pathNames[3]];
                    myRoot.updateAddress("/" + "contact" + "/" + "employment" + "/" + "new-york" + "/" + myRoot.pathNames[3] + "/");
                    break;
                }
                case "los-angeles":
                {
                    myRoot.clickPathNames = ["contact", "employment", "los-angeles", myRoot.pathNames[3]];
                    myRoot.updateAddress("/" + "contact" + "/" + "employment" + "/" + "los-angeles" + "/" + myRoot.pathNames[3] + "/");
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

    }
}
